# =RJabberD - Jabber Server for Ruby
# License:: Ruby's license (see LICENSE file), GNU GPL or GNU LGPL at your option.
# Website:: http://code.google.com/p/rjabberd
  
require 'webrick/server'
require 'connection'
require 'streamparser'

module RJabberD
  class JabberServerError < ::WEBrick::ServerError; end

  Jabber = ::WEBrick::Config::General.dup.update(
      :Port           => 5222
    )

  class JabberServer < ::WEBrick::GenericServer
    def initialize(config = {}, default=Jabber)
      super
      @connections = Hash.new
    end

    # A single client thread.
    def run(sock)
      # Add it to the connections.
      connection = Connection.new(sock, @logger)
      @connections[sock] = connection

      @logger.info("Client connected.")

      # Start the connection handler.
      connection.start

      @logger.info("Client disconnected.")
    end
    
  end
end
